<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //join 方法以指定参数作为分隔符，将所有数组成员连接为一个字符串返回。如果不提供参数，默认用逗号分隔
        var a =[1,2,3,4];
        console.log(a.join(' '));//'1 2 3 4'  空格隔开
        console.log(a.join(''));//'1234'  
        console.log(a.join('|'));//'1|2|3|4'  |隔开
        console.log(a.join());//"1,2,3,4"    不填默认用逗号隔开

        //如果数组成员是undefined或null或空位，会被转成空字符串
        var b = [undefined,null];
        console.log(b.join("#"));// # 

        var c = ["a",,"b"];
        console.log(c.join("-"));//"a--b"

        //数组的join配合字符串的split可以实现数组与字符串的互换
        var arr = ["a","b","c"];
        var myArr = arr.join("");
        console.log(myArr);
        console.log(myArr.split(""));

        var d = ["尚学堂","百战程序员"];
        var d1 = d.join("");
        console.log(d1);
        console.log(d1.split(""));// ['尚', '学', '堂', '百', '战', '程', '序', '员']
        
        
    </script>
</body>
</html>